<?php
include_once('config/config.php');

if ($_GET['id']) {
  $id = $_GET['id'];
  $sql = "SELECT stu.id AS stuid,stu.name AS stuname,sub.id AS subid,sub.name AS subname,score FROM `stu_grade` AS g LEFT JOIN `stu_student` AS stu ON g.stuid = stu.id LEFT JOIN `stu_subject` AS sub ON g.subid = sub.id WHERE g.id = $id";
  $Data = find($sql);
}
if ($_POST) {

  $data = [
    'score' => $_POST['score'],
  ];
  $res = update('grade', $data, "`id` = '$id'");
  if ($res) {
    ShowMsg('修改成功', 'gradelist.php');
  } else {
    ShowMsg('修改失败');
  }
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <?php include_once('common/meta.php') ?>
</head>

<style>
  input[type="file"] {
    display: none;
  }

  label[for="avatar"] {
    width: 200px;
  }
</style>

<body>
  <!--<![endif]-->

  <!-- 引用头部 -->
  <?php include_once('common/header.php') ?>

  <!-- 引用菜单 -->
  <?php include_once('common/nav.php') ?>

  <div class="content">
    <div class="header">
      <h1 class="page-title">新增成绩单</h1>
    </div>
    <ul class="breadcrumb">
      <li><a href="index.php">Home</a> <span class="divider">/</span></li>
      <li><a href="gradelist.php">GradeList</a> <span class="divider">/</span></li>
      <li class="active">GradeAdd</li>
    </ul>

    <div class="container-fluid">
      <div class="row-fluid">

        <div class="btn-toolbar">
          <button class="btn btn-primary" onClick="location='gradelist.php'"><i class="icon-list"></i>成绩列表</button>
          <div class="btn-group">
          </div>
        </div>

        <div class="well">
          <div id="myTabContent" class="tab-content">
            <div class="tab-pane active in" id="home">
              <form method="post" enctype="multipart/form-data">

                <label>学生姓名</label>
                <select name="stuname" disabled id="">
                  <option value="<?php echo $Data['stuid'] ?>"><?php echo $Data['stuname'] ?></option>
                </select>
                <label>学科名称</label>
                <select name="subname" disabled id="">
                  <option value="<?php echo $Data['subid'] ?>"><?php echo $Data['subname'] ?></option>
                </select>
                <label for="">分数</label>
                <input type="number" name="score" value="<?php echo $Data['score'] ?>" class="input-xxlarge" placeholder="请输入分数">

                <label></label>
                <input class="btn btn-primary" type="submit" value="提交" />
              </form>
            </div>
          </div>
        </div>

        <?php include_once('common/footer.php'); ?>

      </div>
    </div>
  </div>
</body>

</html>
<?php include_once('common/script.php'); ?>
<script>

</script>